package com.air.repo.design.pattern.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @Description: java类作用描述
 * @Author: yh
 * @CreateDate: 2018/7/11 15:24
 */
public class AssistantDynamicJdk implements  InvocationHandler{

    Boss boss;
    public AssistantDynamicJdk(Boss boss) {
        this.boss = boss;
    }

    public Object getBossProxy(){
        return  Proxy.newProxyInstance(boss.getClass().getClassLoader(), boss.getClass().getInterfaces(), this);

    }
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return method.invoke(boss,args);
    }
    public static void main(String[] args) throws Throwable{
        Boss boss=new BossImpl();
        System.out.println("代理之前>>>>"+boss.getClass());
        Boss assistant=(Boss)new AssistantDynamicJdk(boss).getBossProxy();

        System.out.println("代理之后>>>>"+assistant.getClass());
        assistant.readNews();
        assistant.getTea();
    }



}
